import { Cache, CacheConstant } from '@/plugin';
import { Menu } from '@/model/common/Menu';
import { Dict, DictType } from '@/model/common';
import { UserDetailDTO } from '@/model/user';

export default {
    token: (state: any, token: string) => {
        state.token = token;
        Cache.setWithValidDuration(CacheConstant.TOKEN, token, import.meta.env.VITE_APP_TOKEN_VALID_DURATION as string);
    },
    user: (state: any, user: UserDetailDTO) => {
        state.user = user;
        Cache.set(CacheConstant.USER, user);
    },
    menus: (state: any, menus: Menu[]) => {
        state.menus = menus;
        Cache.set(CacheConstant.MENUS, menus);
    },
    dict: (state: any, dict: { type: DictType; data: Dict[] }) => {
        const storeDicts: Map<DictType, Dict[]> = state.dict;
        storeDicts.set(dict.type, dict.data);
        state.dict = storeDicts;
    },
    chatId: (state: any, chatId: string) => {
        state.chatId = chatId;
        Cache.set(CacheConstant.CHAT_ID, chatId);
    },
};
